<template>
	<view>
		
		<view style="width: 100%; height: 50px; font-size: 17px; font-weight: bold; text-align: center; line-height: 50px;">{{loc}}</view>
		
		<view class="goodlist_item" v-for="(item, i) in goodlist" :key="i" @click="gotodetail(item)">
			<view class="left">
				<image :src="item.pictures[0]" style="width: 100px;"></image>
			</view>
			<view class="right">
				<view style="font-weight: bold; font-size: 15px;">{{item.name}}</view>
				
				<view>卖家{{item.contact_way_category}}: {{item.contact_way}}</view>
			
				<view class="goods_price">￥{{item.price | tofixed}}</view>
			</view>
		</view>	
	</view>
</template>

<script>
	export default {
		data() {
			return {	
				goodlist: [],
				loc: ""
			};
		},
		onLoad(e) {
		//	this.queryobj.query = e.query || ''
		//	this.queryobj.cid = e.cid || ''
			this.loc = e.loc
			this.cha()
		//	this.get_goodslist()
		},

		onReachBottom() {
			return uni.showToast({
				title: '我也是有底线的！',
				icon:'none',
				duration: 500
			})	
		},
		onPullDownRefresh() {
			uni.stopPullDownRefresh()
		},
		methods: {
			async cha(){
				const db = uniCloud.database();
				//用await保证函数彻底执行完，数据返回完毕后再执行下面的代码,limit(1),取第一条数据，get(),执行查询操作
				this.res = await db.collection("category").get();
			
				//获得的数据藏在res.result.data里，取值就行了
				this.goodlist = this.res.result.data.filter(x => x.address === this.loc) 
	
			},
		/*	async get_goodslist() {
				this.isloading = true
				const {data: res} = await uni.$http.get('/api/public/v1/goods/search', this.queryobj)
				if(res.meta.status == 200){
					console.log(res)
					this.total = res.message.total
					this.goodlist = [...this.goodlist, ...res.message.goods]
					this.isloading = false
				}else{
					this.isloading = false
					return uni.$failmsg()
				}
			},*/
			gotodetail(item) {
				uni.navigateTo({
					url: '/subpkg/goods_detail/goods_detail?goods_id=' + item._id
				})
			}
		},
		filters: {
			tofixed(num) {
				return Number(num).toFixed(2)
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: white;
	}
	.goodlist_item {
		height: 100px;
		border: 1px solid #efefef;
		display: flex;
	}
	.left {
		height: 100px;
	}
	.left image {
		height: 100%;
	}

	.goods_price {
		margin-bottom: 15px;
		font-size: 18px;
		color: red;
		font-weight: bold;
	}
	.right {
		margin-left: 5px;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		width: 100%;
	}

</style>
